import resources.RegistNetPropertyBundle;

/* [start] 	initializes gui variables */
RegistNetPropertyBundle bundle = RegistNetPropertyBundle.getInstance("/resources/registnet");

String _logo =  bundle.getProperty("registnet.logo");

String _administrator = bundle.getProperty("registnet.login.form.user.administrator");

String _authors = bundle.getProperty("registnet.user.registrar.toolbar.authors");
String _help = bundle.getProperty("registnet.user.registrar.toolbar.help");

String _welcome = bundle.getProperty("registnet.user.registrar.welcome");
String _sign_out = bundle.getProperty("registnet.user.registrar.sign_out");
String _my_account = bundle.getProperty("registnet.user.registrar.my_account");
String _home = bundle.getProperty("registnet.user.registrar.home");
String _menu = bundle.getProperty("registnet.user.registrar.menu");
String _search = bundle.getProperty("registnet.user.registrar.search");

HashMap map_tab = new HashMap();
/* [end] */



/* [start]	defines an event listener;
			when a tab is closed, it is removed from the hashmap */
private class CloseTabEventListener implements EventListener {
	private String source;
	
	public CloseTabEventListener (String source){
		this.source = source;
	}
			
	public void onEvent(Event event) throws UiException {
		map_tab.remove(source);
	}
}
/* [end] */



/* [start]	retrieves session variables */
String _user = session.getAttribute("_username");
String _user_type = session.getAttribute("_user_type");
String _office = session.getAttribute("_office");
/* [end] */



/* [start]	checks if session is valid */
boolean _isValidSession = false;
try{
	_isValidSession = _user_type.equals(_administrator);
}catch(Exception e) { _isValidSession = false; }
/* [end] */



showSystemProperties(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals("Year/Semester")){
			Component win = Executions.createComponents("../../WEB-INF/macros/system/year_semester.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}

showUsers(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals("Active Accounts")){
			Component win = Executions.createComponents("../../WEB-INF/macros/users/active_users.zul", tabpanel, null);
		}
		else if(object.equals("Pending Accounts")){
			Component win = Executions.createComponents("../../WEB-INF/macros/users/inactive_users.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}

showLogs(String object){
	if(!map_tab.containsKey(object)){		
		Tabs tabs = stage.getTabs();
		Tab tab = new Tab(object);
		tab.setClosable(true);
		tab.setParent(tabs);
		tab.addEventListener("onClose", new CloseTabEventListener(object));
		
		Tabpanels tabpanels = stage.getTabpanels();
		Tabpanel tabpanel = new Tabpanel();
		tabpanel.setSclass("background_light_blue");
		tabpanel.setParent(tabpanels);
		stage.setSelectedPanel(tabpanel);
		
		map_tab.put(object, tab);
		
		if(object.equals("View Logs")){
			Component win = Executions.createComponents("../../WEB-INF/macros/logs/view_logs.zul", tabpanel, null);
		}
		else if(object.equals("Rollback")){
			Component win = Executions.createComponents("../../WEB-INF/macros/logs/rollback.zul", tabpanel, null);
		}
	}
	else
		map_tab.get(object).setSelected(true);
}



/* [start]	signs out the user*/
void signOut(){
	session.invalidate();
	Executions.sendRedirect("../../index.zul");
}
/* [end] */